<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of PageController
 * Klasa, z której dziedziczone będą wszystkie strony
 * @author juwking
 */
abstract class PageController extends ComponentBase {

    protected $menuArray;

    function __construct() {
        parent::__construct();
        $this->initSite();
    }

    private function initSite() {
        $this->initMenuBar();
        $this->initTemplate();
    }

    protected function initTemplate() {

        $this->smarty->assign('title', 'Mailing');
        $this->smarty->assign('css', $this->getStyles());
        $this->smarty->assign('scripts', $this->getScripts());
        #  $this->smarty->assign('page', &$this);
        $this->smarty->assign('source', $this->getPageName());
        $this->smarty->assign('menuBar', $this->menuArray);
        $this->smarty->assign('content', $this->getContent());
    }

    /**
     * Przeciążyć aby zmienić content
     * @return String
     */
    function getContent() {
        
    }

    function getStyles() {
        return 'css/style.css';
    }

    function getScripts() {
        $scripts[0] = "ajax/ajax.js";
        $scripts[1] = "ajax/jquery-1.6.2.min.js";
        return $scripts;
    }

    /**
     * Przeciazenie aby nadac nazwe podstrony
     */
    abstract function getPageName();

    /**
     *
     * @param string $action Nazwa metody będąca pseudo-zdarzeniem wywołanej z metody.
     */
    function executeAction($action=null) {
        if (isset($action)) {
            
            $actions = explode('/', $action);
            if (method_exists($this, $actions[0])) {
                $this->$actions[0]($actions[1]);
            }
        }
        else
        {
            $this->defaultAction();
        }
    }
    function defaultAction(){
        $this->display("404.tpl");
    }
    /**
     * Inicjacja paska menu
     */
    protected function initMenuBar() {
        $this->menuArray = array(
            array('title' => "Główna strona", 'link' => "home", 'active' => false),
            array('title' => "List mailingowe", 'link' => "mailing", 'active' => false),
            array('title' => "Użytkownicy", 'link' => "users", 'active' => false),
            array('title' => "Grupy Użytkowników", 'link' => "groups", 'active' => false),
            array('title' => "Organizacje", 'link' => "orgs", 'active' => false),
            array('title' => "Klienci", 'link' => "client", 'active' => false),
            array('title' => "Kategorie klientów", 'link' => "category", 'active' => false),
            array('title' => "Profil", 'link' => "profile", 'active' => false)
        );
    }

    public function getMenubar() {
        return $this->menuArray;
    }

}

?>
